package com.example.hotel.blImpl.admin;

import com.example.hotel.bl.admin.AdminService;

import com.example.hotel.bl.hotel.HotelService;
import com.example.hotel.data.admin.AdminMapper;
//import com.example.hotel.bl.hotel.HotelService;


import com.example.hotel.enums.UserType;
import com.example.hotel.po.User;
import com.example.hotel.vo.HotelBindingVO;
import com.example.hotel.vo.HotelVO;
import com.example.hotel.vo.ResponseVO;
import com.example.hotel.vo.UserForm;




import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author:
 * @Date: 2021-06-27
 */
@Service
public class AdminServiceImpl implements AdminService {
    private final static String ACCOUNT_EXIST = "账号已存在";

    @Autowired
    AdminMapper adminMapper;

    @Autowired
    HotelService hotelService;

    @Autowired
    BCryptPasswordEncoder passwordEncoder;

    @Override
    public ResponseVO addManager(UserForm userForm) {
        User user = new User();
        user.setEmail(userForm.getEmail());
        user.setPassword(passwordEncoder.encode(userForm.getPassword()));
        user.setUserName("HotelMgr");
        user.setCredit(0);
        user.setPhoneNumber("9999");
        user.setUserType(UserType.HotelManager);
        try {
            adminMapper.addManager(user);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return ResponseVO.buildFailure(ACCOUNT_EXIST);
        }
        return ResponseVO.buildSuccess(true);
    }

    @Override
    public List<User> getAllManagers() {
        return adminMapper.getAllManagers();
    }

    @Override
    public List<User> getAllClients() {
            return adminMapper.getAllClients();
    }

    @Override
    public boolean bindHotelMgr(HotelBindingVO hotelBindingVO) {
        return hotelService.bindHotelMgr(hotelBindingVO) ;
    }

    @Override
    public List<HotelVO> selectManagedBy(Integer mgrId) {
        return hotelService.selectManagedBy(mgrId);
    }
}

